package com.memory.monitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.memory.monitor.annotation.AuthCheck;
import com.memory.monitor.common.BaseResponse;
import com.memory.monitor.common.DeleteRequest;
import com.memory.monitor.common.ResultUtils;
import com.memory.monitor.constant.UserConstant;

import com.memory.monitor.model.dto.market.MarketAddRequest;
import com.memory.monitor.model.dto.market.MarketQuerryRequest;
import com.memory.monitor.model.dto.market.MarketUpdateRequest;
import com.memory.monitor.model.entity.Market;
import com.memory.monitor.service.MarketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/market")
@Slf4j
public class MarketController {
    @Resource
    private MarketService marketService;

    /**
     * 分页获取列表
     *
     * @param marketQuerryRequest

     * @return
     */
    @PostMapping("/list/page")
    @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
    public BaseResponse<Page<Market>> listByPageMarket(@RequestBody MarketQuerryRequest marketQuerryRequest) {
        long current = marketQuerryRequest.getCurrent();
        long size = marketQuerryRequest.getPageSize();
        // Page<User> userPage = userService.page(new Page<>(current, size),
        //         userService.getQueryWrapper(userQueryRequest));
        Page<Market> marketPage = marketService.page(new Page<>(current, size));

        return ResultUtils.success(marketPage);
    }
    /**
     * 增加信息  返回id
     * @param marketAddRequest
     * @return
     */
    @PostMapping("/add")
    public BaseResponse<Long> addMarket(@RequestBody MarketAddRequest marketAddRequest){
        Long id = marketService.addMarket(marketAddRequest);
        return ResultUtils.success(id);
    }

    /**
     * 修改信息 返回boolean
     *
     * @param marketUpdateRequest

     * @return
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateMarket(@RequestBody MarketUpdateRequest marketUpdateRequest){
        Boolean result= marketService.updateMarket(marketUpdateRequest);
        return ResultUtils.success(result);
    }
    /**
     * 删除信息 返回boolean
     *
     * @param deleteRequest

     * @return
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteMarket(@RequestBody DeleteRequest deleteRequest){
        Boolean result = marketService.deleteMarket(deleteRequest);
        return ResultUtils.success(result);
    }

}